package com.hqj.service;

import com.hqj.dao.HomesDao;
import com.hqj.entity.Homes;
import com.hqj.util.ReturnValueUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
@Service
public class HomesServiceI implements BaseService<Homes> {

    @Autowired
    private HomesDao hd;

    @Override
    public List<Homes> find(Homes homes) {
        List<Homes> list = hd.find(homes);
        return list;
    }

    @Override
    public Homes get(Homes homes) {
        List<Homes> list = this.find(homes);
        homes = list.size()>0?list.get(0):null;
        return homes;
    }

    @Override
    public Map<String, Object> add(Homes homes) {
        //判断strDate是否有值
        if(homes.getStrDate()!=null){
            try {
                homes.setBuildDate(new SimpleDateFormat("yyyy-MM-dd").parse(homes.getStrDate()));
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        int i = hd.add(homes);
        return ReturnValueUtil.aer(i,"新增");
    }

    @Override
    public Map<String, Object> edit(Homes homes) {
        //判断strDate是否有值
        if(homes.getStrDate()!=null){
            try {
                homes.setBuildDate(new SimpleDateFormat("yyyy-MM-dd").parse(homes.getStrDate()));
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        int i = hd.edit(homes);
        return ReturnValueUtil.aer(i,"编辑");
    }

    @Override
    public Map<String, Object> remove(int id) {
        int i = hd.remove(id);
        return ReturnValueUtil.aer(i,"删除");
    }
}
